package com.zhiyou.crud.service.impl;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.crud.bean.user;
import com.zhiyou.crud.dao.userMapper;
import com.zhiyou.crud.service.userService;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
public class userServiceImpl implements userService {
@Autowired
userMapper usermapper;

@Override
public user getUser(String usName, String usPassword) {
	user u=new user();
	u.setUsname(usName);
	u.setUspassword(usPassword);
	return usermapper.selectOne(u);
}

@Override
public int addUser(user use) {
	int i=usermapper.insertSelective(use);
	return i;
}

@Override
public boolean checkUser(String usname) {
	Example example = new Example(user.class);
   Criteria  criteria=example.createCriteria();
   criteria.andEqualTo("usname",usname);
   long count=usermapper.selectCountByExample(example);
	return count==0; 
}

}
